
import get from '@dfeidao/atom-web/local/get';
import fire from '@dfeidao/atom-web/msg/fire';
import nodejs from '@dfeidao/atom-web/msg/nodejs';
import error from '@dfeidao/atom-web/msgbox/error';
import success from '@dfeidao/atom-web/msgbox/success';
import s_get from '@dfeidao/atom-web/storage/get';

import { IFeidaoAiBrowserComponent } from '@dfeidao/web/interfaces';
import hide_loading from '../../atom/hide-loading';
import show_loading from '../../atom/show-loading';


export default async function a002(fd: IFeidaoAiBrowserComponent) {
	const _id = get(fd, 'g_id');
	const zj = get(fd, 'zj');

	const prid = await s_get('productid');

	const connector = fd.data.node.querySelector<HTMLSelectElement>('#connector').value;

	const query = {
		_id,
		connector,
		productid: prid
	};
	show_loading();
	const res = await nodejs('roler/zj-000006/s001', query);
	hide_loading();
	const role_allot_id = get(fd, 'role_allot_id');
	const ids = get(fd, 'ids');
	if (res === 'success') {
		if (zj === 'zj-000011') {
			fire('zj-000011', 'ec-003', { role_allot_id, _id, ids });
		} if (zj === 'zj-000004') {
			fire('zj-000004', 'ec-003', role_allot_id, _id, ids);
		}
		fire('zj-000006', 'eu-001');

		success('保存成功');

	} else {
		error('保存失败');


	}
}
